//
//  CityDic.m
//  05 - 作业
//
//  Created by 韩旭 on 16/7/9.
//  Copyright © 2016年 基础. All rights reserved.
//

#import "CityDic.h"
@implementation CityDic
- (instancetype)init {
    self = [super init];
    if (self) {
        _dicCity = [[NSMutableDictionary alloc] init];
    }
    return self;
}
- (NSMutableArray *)gruop:(NSMutableDictionary *)cityDic {
    NSMutableArray *arrEncoding = [NSMutableArray array];
    for (NSString *encoding in cityDic) {
        [arrEncoding addObject:encoding];
    }
    NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"self" ascending:YES];
   [arrEncoding sortUsingDescriptors:@[sort]];
    NSMutableArray *arrAll = [NSMutableArray array];
    for (NSString *string in arrEncoding) {
        if ([string hasSuffix:@"0000"]) {
            NSMutableDictionary *dicPro = [NSMutableDictionary dictionary];
            [dicPro setObject:cityDic[string] forKey:@"AProvince"];
            NSMutableArray *arrCitys = [NSMutableArray array];
            [dicPro setObject:arrCitys forKey:@"ArrCitys"];
            [arrAll addObject:dicPro];
        } else if ([string hasSuffix:@"00"] && ![string hasSuffix:@"000"]) {
            NSMutableDictionary *dicCitys = [NSMutableDictionary dictionary];
            [dicCitys setObject:cityDic[string] forKey:@"ACitys"];
            NSMutableArray *arrAreas = [NSMutableArray array];
            [dicCitys setObject:arrAreas forKey:@"ArrAreas"];
            NSDictionary *dicPro = [arrAll lastObject];
            [dicPro[@"ArrCitys"] addObject:dicCitys];
        } else {
            NSMutableDictionary *dicAreas = [NSMutableDictionary dictionary];
            [dicAreas setObject:cityDic[string] forKey:@"Areas"];
            NSDictionary *dicCitys = [[[arrAll lastObject] objectForKey:@"ArrCitys"] lastObject];
            [dicCitys[@"ArrAreas"] addObject:dicAreas];
        }
    }
    return arrAll;
}
- (NSMutableDictionary *)dicCity {
    return _dicCity;
}

@end
